package com.java3_12;

public class People implements Comparable{
    private String name;
    private int age;

    public People() {
    }

    public People(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Object o) {
        if(this == o)
            return 0;
        if (o instanceof People people){
            int value = Integer.compare(this.age,people.age);
            if(value != 0){
                return value;
            }
            return this.name.compareTo(people.name);
        }
        throw new RuntimeException("类型不正确");

    }

    @Override
    public String toString() {
        return "People{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
